<?php
class ArticleController extends Controller 
{
	function __construct(){
		View::setLayout('admin');
	}

	function show()
    {

		$list	=	Article::getList(null);

		$this->assign('list',	$list);
		$this->display();
    }

	function add()
	{
		if(!empty($_POST))
		{
			$aid	=	Article::add(array(
				'pubtime'	=>	Lib::post('pubtime', 'int', time()),
				'title'		=>	Lib::post('title'),
				'content'	=>	Lib::post('content'),
				'keywords'	=>	Lib::post('keywords'),
				'siteid'	=>	Lib::post('siteid', 'int'),
				'cateid'	=>	Lib::post('cateid', 'int'),
			));
			if($aid){
				Show::notice('添加成功，<a href="'.Lib::url('./?a=article.read&aid='.$aid).'">查看</a>',
					'./?a=article.add');
			}
			else{
				Show::notice('添加失败', './?a=article.add');
			}
		}

		$this->display();
	}

	function modify()
	{
		$aid	=	Lib::get('id', 'int');
		$art	=	Article::get($aid);
		if(!$art)
		{
			Show::notice('no such article', './?a=article');
		}
		
		if(!empty($_POST))
		{
			if(Article::update($aid, array(
				'title'		=>	Lib::post('title'),
				'content'	=>	Lib::post('content'),
				'keywords'	=>	Lib::post('keywords'),
				'siteid'	=>	Lib::post('siteid', 'int'),
				'cateid'	=>	Lib::post('cateid', 'int'),
			))){
				Show::notice('修改成功', './?a=article');
			}
			else{
				Show::notice('修改失败', './?a=article.modify&id='.$aid);
			}
		}
		
		$this->assign('article',	$art);
		$this->display();
	}

	function read()
	{
		$aid	=	Lib::get('id', 'int');
		$art	=	Article::get($aid);
		if(!$art)
		{
			//Show::go400("no such article");
			Show::notice('no such article', './?a=article');
		}
		
		$this->assign('article', $art);
		$this->display();
	}
	
}
?>